package com.caizi.thread;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Test {

    static List<Integer> list = new ArrayList<Integer>();

    public static void main(String[] args) {
        ExecutorService newFixedThreadPool = Executors.newFixedThreadPool(9);
        for (int i = 0; i < 100; i++) {
            newFixedThreadPool.execute(new Task(i));
        }
        newFixedThreadPool.shutdown();
        System.out.println("it's not over");
        do {
            System.out.println("it's not over");
        } while (list.size() != 98);
        System.out.println("it's really over" + list.size());
    }
}

class Task implements Runnable {
    int i;

    public Task(int i) {
        this.i = i;
    }

    @Override
    public void run() {

        System.out.println(Thread.currentThread().getName());
        // try {
        // Thread.sleep(50l);
        // } catch (InterruptedException e) {
        // e.printStackTrace();
        // }
        System.out.println(Thread.currentThread().getName() + "：：：" + i);
        synchronized (Test.list) {
            Test.list.add(i);
        }
    }
}
